import 'package:eh_mobile/common/routers/index.dart';
import 'package:eh_mobile/common/utils/log.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'common/langs/translation_service.dart';
import 'common/store/config_store.dart';
import 'common/style/theme.dart';
import 'common/utils/screen_util.dart';
import 'global.dart';

Future<void> main() async {
  Global.init().then((value) => runApp(const MyApp()));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // 初始化全局尺寸常量类
    ScreenUtils().init(context);

    return ScreenUtilInit(
      designSize: const Size(390, 844),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        return GetMaterialApp(
          title: 'Ecore Home',
          theme: AppTheme.dark,
           showPerformanceOverlay: false, //显示性能图层分析工具banner
          debugShowCheckedModeBanner: true, //显示debug图标
          initialRoute: RouterPages.INITIAL,
          getPages: RouterPages.routes,
          builder: EasyLoading.init(),
          translations: TranslationService(),
          navigatorObservers: [RouterPages.observer],
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          supportedLocales: ConfigStore().languages,
          locale: ConfigStore().locale,
          fallbackLocale: const Locale('en', 'US'),
          enableLog: true,
          logWriterCallback: Log.write,
        );
      },
    );
  }
}

